//
//  Person_D_one.m
//  K-Music
//
//  Created by CHUN on 16/1/14.
//  Copyright © 2016年 CHUN. All rights reserved.
//

#import "Person_D_one.h"
#import "Person_D_two.h"
#import "InteractionCell.h"
#import "RecordWork_Medel.h"

@interface Person_D_one ()<UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate>
{
    RecordWork_Medel*mode;
}

@property(nonatomic,strong)NSMutableArray*allMusicData;
@property (nonatomic, strong) UITableView * Person_D_one;

@end

@implementation Person_D_one

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = RGB(241, 241, 241);
    
    [self get_record];
    
    mode = [[RecordWork_Medel alloc]init];
    
    [self createUI];
    
}

- (void)createUI
{
    _Person_D_one = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-210) style:UITableViewStylePlain];
    _Person_D_one.delegate = self;
    _Person_D_one.dataSource = self;
    _Person_D_one.showsVerticalScrollIndicator = NO;
    _Person_D_one.separatorStyle = UITableViewCellSeparatorStyleNone;
    _Person_D_one.backgroundColor = RGB(241, 241, 241);
    [self.view addSubview:_Person_D_one];

}


-(void)get_record{
    
    [MBProgressHUD showWithStatus:@"加载中..." toView:self.view];
    
    AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager manager];
    
    NSString * userId = [NSString stringWithFormat:@"%@",[FileStorage NSUserDefault_getObjectForKey:User_id]];
    
    NSString*infoStr11=[NSString stringWithFormat:@"/api/records/user_id/%@/shared_records?page=0&size=20&sort=createdDate,DESC",userId];
    
    NSString *intactURL = [MyBaseUrl stringByAppendingString:infoStr11];
    
    NSString * token = [FileStorage NSUserDefault_getObjectForKey:access_token];
    
    //    创建请求
    manager.requestSerializer =[AFHTTPRequestSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json"
                     forHTTPHeaderField:@"Accept"];
    [manager.requestSerializer setValue:[NSString stringWithFormat: @"Bearer %@",token]
                     forHTTPHeaderField:@"Authorization"];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager GET:intactURL parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        
        NSLog(@"成功GET --> %@", dic);
        NSArray *arr = [[dic objectForKey:@"body"] objectForKey:@"content"];
        _allMusicData = [NSMutableArray array];
        
        for (int i = 0; i<arr.count; i++) {
            [mode initDic:[[arr objectAtIndex:i] objectForKey:@"record"]];
            [_allMusicData addObject:mode];
        }
        
        [_Person_D_one reloadData];
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"%@",error);
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [MBProgressHUD showErrorWithStatus:@"数据获取失败" toView:self.view];
        
    }];
}

#pragma mark-----------------------UiTbaleView代理方法------------------------------------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _allMusicData.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 126;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString*inf=@"InteractionCell";
    
    InteractionCell*cell=[tableView  dequeueReusableCellWithIdentifier:inf];
    
    if (cell == nil) {
        
        cell = [[[NSBundle mainBundle]loadNibNamed:@"InteractionCell" owner:self options:nil ] firstObject];
        
    }
    
#warning 播放  暂时 用第一个用户DATA
    mode = _allMusicData[indexPath.row];
    cell.Itt_name.text=[NSString stringWithFormat:@"%@",mode.userId];
    cell.info_text.text=[NSString stringWithFormat:@"%@",mode.name];
    cell.infoter_text.text=[NSString stringWithFormat:@"%@",mode.descriptionD];
    
    cell.text1.text=[NSString stringWithFormat:@"%@",mode.totalPlay];
    cell.text2.text=[NSString stringWithFormat:@"%@",mode.totalGift];
    
    cell.text3.text=[NSString stringWithFormat:@"%@",mode.totalShare];
    
    cell.text4.text=[NSString stringWithFormat:@"%@",mode.totalPlayMonthly];
    
    cell.mm_text.text=[NSString stringWithFormat:@"%@",mode.size];
    [cell.image_photo sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",mode.pictureUrl]]];
    
    cell.image_photo.layer.cornerRadius= cell.image_photo.width/2 ;
    cell.image_photo.layer.masksToBounds = YES;
    
    
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
